<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>数据表备份</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__COMMON__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="backup('{$table}')"><i class="layui-icon"></i>备份</button>
        <span class="x-right" style="line-height:40px">共有数据：{$list|count} 条</span>
      </xblock>
      <table class="layui-table"  lay-filter="mytable">
        <thead>
          <tr>
            <th lay-data="{field:'time', width:180}">备份时间</th>
            <th lay-data="{field:'engine'}">备份名称</th>
            <th lay-data="{field:'author', width:120}">文件大小</th>
            <th lay-data="{field:'collation', width:80}">类型</th>
        <th lay-data="{field:'caozuo', width:200}">操作</th>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
          <tr>
            <td>{$vo.time|date="Y/m/d H:i:s",###}</td>
            <td>{$vo.filename}</td>
            <td>{:format_size($vo.size)}</td>
            <td>{$vo.compress}</td>
            <td class="td-manage">
              <a href="{:url('admin/Database/download',['t'=>$table,'time'=>$vo.time])}" class="layui-btn layui-btn-normal layui-btn-xs">下载</a>
              <a href="javascript:;" onclick="restore('{$table}','{$vo.time}')" class="layui-btn layui-btn-normal layui-btn-xs">还原</a>
              <a href="javascript:;" onclick="del('{$table}','{$vo.time}')" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>
            </td>
          </tr>
        {/volist}
        </tbody>
      </table>
    </div>
    <script>
      var table;
      var repairAll;
      layui.use('table', function(){
          table= layui.table;
          //转换静态表格
          table.init('mytable', {
              id:"mytable"
              ,height: 600 //设置高度
              ,limit:600
          });
      });

      //单表备份
      function backup(tablename){
        $.post("{:url('admin/Database/dbbackup')}",{t:tablename},function(res){
          layer.msg(res.msg,{time:1000},function () {
              location.reload();
          });
        },'json');
      }

      //数据还原
      function restore(tablename,time){
          $.post("{:url('admin/Database/restore')}",{t:tablename,time:time},function(res){
              layer.msg(res.msg,{time:1000},function () {
                  location.reload();
              });
          },'json');
      }
      //备份删除
      function del(tablename,time){
          $.post("{:url('admin/Database/del')}",{t:tablename,time:time},function(res){
              layer.msg(res.msg,{time:1000},function () {
                  location.reload();
              });
          },'json');
      }
      //备份删除
      // function downloads(tablename,time){
      //     $.post("{:url('admin/Database/download')}",{t:tablename,time:time},function(res){
      //         layer.msg(res.msg,{time:1000},function () {
      //             location.reload();
      //         });
      //     },'json');
      // }
    </script>

  </body>

</html>